package iscript.gameFramework.NetService.data 
{
	import be.boulevart.as3.security.RC4;

	public class KeyTable 
	{		
		private function parse(resultStr:String):void
		{
			var arr:Array = resultStr.split("\r\n");//换行
			for each(var key:String in arr)
			{
				if(key!=""){
				var data:String = RC4.decrypt(key, _decryptKey);
				_keyTables.push(data);
				}				
			}
		}
		
		public function get content():Vector.<String>
		{
			return _keyTables;
		}
		
		
		public function randomIndex():int {
			return  Math.random() * _keyTables.length;
			}

		
		public function KeyTable(data:String) 
		{
			if (data == null) throw new Error("not keytable data");			 
			parse(data);
		}
		
		private var _keyTables:Vector.<String> = new Vector.<String>();;		
		static private var _decryptKey:String = "going_!@#$%^&123";
		
		static private var _instance:KeyTable;		
		
		static public function  createInstance(data:String):void {
			    _instance = new KeyTable(data);
			}
		
		static public function  getInstance():KeyTable {
			  if(_instance==null) throw new Error("plase set keytable");	
			  // if (_instance == null) _instance = new KeyTable(data);
			  // if (_instance._keyTables.length == 0) throw new Error("not keytable data");	
			   return _instance;
			}
		
	}

}